<%@page import="news.util.PageController"%>
<%@page import="news.entity.News"%>
<%@page import="news.biz.NewsBiz"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@include file="judge.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'newsList.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<style>
	td{
		text-align: center;
	}
	</style>
  </head>
 
 <%
 	//获取当前页码
 	String pageIndex=request.getParameter("pageIndex");
 	//如果是首页（没有页码）
 	if(pageIndex==null){
 		pageIndex="1";
 	}
 	//转化为整数
 	int currentPage=Integer.parseInt(pageIndex);
 	
 	//每个页面显示的新闻条数
 	int pageSize=3;
 	
 	NewsBiz newsBiz=new NewsBiz();
 	//得到总条数
 	int count=newsBiz.getNewsCount();
 	//根据总条数和每页的个数的到总页数
 	PageController pc=new PageController();
 	int totalPages=pc.getTotalPage(count, pageSize);
 			
 	//处理首页点击上一页和尾页点击下一页
 	if(currentPage<1){
 		currentPage=1;
 	}else if(currentPage>totalPages){
 		currentPage=totalPages;
 	}
 
 	//调用分页函数
 	List<News> list=newsBiz.getNewsByPage(pageSize, currentPage);
 %>
  <body background="pic/ManBgroud.gif">
    <a href="admin/addNews.jsp">新增新闻</a>
    <table style="width: 80%; border: 1px solid #006666">
    	<tr>
				<th>编号</th>
				<th>标题</th>
				<th>发布人儿</th>
				<th>发布时间</th>
				<th>类别</th>				
				<th>操作</th>
			</tr>
			<%
				for(int i=0;i<list.size();i++){
					News news=list.get(i);
			%>
			<tr>
				<td><%=news.getNewId() %></td>
				<td><%=news.getNewsTitle() %></td>
				<td><%=news.getAdminId().getAdminName() %></td><!-- getAdminId()是news中adminid的get方法 -->
				<td><%=news.getNewsCTime() %></td>
				<td><%=news.getBoardId().getBoardName() %></td>
				<td><a href="">编辑</a>|<a href="">删除</a></td>
			</tr>
			<%} %>
			<tr>
				<td colspan="6" align="center">
						<a href="admin/newsList.jsp?pageIndex=1" >首页</a>
						<a href="admin/newsList.jsp?pageIndex=<%=currentPage-1 %>" >上一页</a>
						<a href="admin/newsList.jsp?pageIndex=<%=currentPage+1 %>" >下一页</a>
						<a href="admin/newsList.jsp?pageIndex=<%=totalPages %>" >尾页</a>
				</td>
			</tr>
			
    </table>
  </body>
</html>
